home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / DEV / C-H / CHexDmpDA.cpt / Hex Dump DA / buffer.HexDumpDA.c < prev    next >
Text File  |  1988-05-23  |  944b  |  47 lines

  1. /* buffer.HexDumpDA.c
  2.  *
  3.  *    Routines for managing a window into the contents of a file.
  4.  *
  5.  *    SetBuffer(char *) set the pointer "buffer" to point to a given space
  6.  *    FillBuffer( start, finish ) assure that the data from offset "start" 
  7.  *        to offset "finish" of the file is in the data buffer
  8.  */
  9.  
  10. #include <FileMgr.h>
  11.  
  12. #define BUFSIZE     2048L
  13. char         buffer[BUFSIZE];
  14.  
  15. extern    long         firstByte;
  16. extern    int         nLines;
  17. extern    int            fileRef;
  18.  
  19. long lmax(a,b)
  20. long a,b;
  21. {
  22.     return ((a>b) ? a : b);
  23. }
  24.  
  25. #define PAD            256L
  26.  
  27. ReadFrom(i)
  28. long i;
  29. {
  30.     /* Maintains buffer and firstByte */
  31.     /* Must assure that nLines of data are in buffer */
  32.     /* If not:
  33.     /*        firstByte = max(i-PAD, 0)
  34.     /*         read BUFSIZE bytes at firstByte
  35.     */
  36.  
  37.     long count;
  38.     
  39.     if ((i<firstByte) || (i + nLines*16>firstByte+BUFSIZE) || (firstByte<0)) {
  40.         firstByte = lmax( i-PAD, 0L );
  41.         SetFPos( fileRef, fsFromStart, firstByte );
  42.         count = BUFSIZE;
  43.         FSRead( fileRef, &count, &buffer );
  44.     }
  45. }
  46.  
  47.